/*
 * Created by SharpDevelop.
 * User: David
 * Date: 2006-12-01
 * Time: 09:43
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;

namespace tools
{
	/// <summary>
	/// Randomizer is a singelton class which gives you random numbers in the range you specify in
	/// each seperate call to method Next.
	/// </summary>
	public sealed class Randomizer
	{
		#region members
		
		/// <summary>
		/// The one instance of Randomizer
		/// </summary>
		private static Randomizer		m_Instance = new Randomizer();
		/// <summary>
		/// The Random object creating all the random numbers
		/// </summary>
		private Random					m_Generator;
		
		#endregion
		
		#region constructors
		
		/// <summary>
		/// Constructor, initializes members
		/// </summary>
		private Randomizer()
		{
			m_Generator = new Random(DateTime.Now.Millisecond);
		}
		
		#endregion
		
		#region methods
		
		/// <summary>
		/// Gets you the next random number between inclusive delimiters. If you missuse this class,
		/// e.g. by setting the minimum value to a larger number than the maximum value, you will
		/// get the minimum value back.
		/// </summary>
		/// <param name="min">The minimum number this method can return at this one call</param>
		/// <param name="max">The maximum number this method can return at this one call</param>
		/// <returns>The generated random mumber</returns>
		public int Next(int min, int max)
		{
			int next;
			
			try
			{
				next = m_Generator.Next(min, max + 1);
			}
			catch
			{
				next = min;
			}
			
			return next;
		}
		
		#endregion
		
		#region properties
		
		/// <summary>
		/// The one instance (get)
		/// </summary>
		public static Randomizer Instance
		{
			get
			{
				return m_Instance;
			}
		}
		
		#endregion
	}
}
